<?php
  require_once '../classes/ConnectionDB.php';
  require_once '../classes/UtenteManager.php';
  require_once '../classes/LoadProperties.php';
  require_once '../classes/DisciplinaManager.php';
  $properties = new LoadProperties();
  $properties->initServices();
  $connection = ConnectionDB::getInstance()->connectToDB();
  $codiceUtente = $_GET['codiceUtente'];
  $result = UtenteManager::getInstance()->getUtente($connection, $codiceUtente);
  if ($result != null)
  {
    $disciplinaInsegnata = UtenteManager::getInstance()->getDisciplinaByCodice($connection, $codiceUtente);
    $elencoDiscipline = DisciplinaManager::getInstance()->getDiscipline($connection);
  }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
      <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
      <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
      <title>Profilo utente</title>
      <style type="text/css">
        @import url("../css/style.css");
        a#viewcss{color: #00f;font-weight: bold}
        #utenteBox {
          padding-top: 5%;
        }

        #utenteBoxCont
        {
          padding-top: 5%;
          padding-top: 1%;
          padding-left: 11%;
        }
        #utenteBox_contentBoxBg {
          background-color :  #5767ab;

        }

      </style>
      <script type="text/javascript">
        path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
        window.onload = function(){

          var utenteBox = new GlassBox();
          utenteBox.init( 'utenteBox', '800px', '590px', 'hidden','',false);
          utenteBox.ipos();
          utenteBox.appear();
        }

        function updateDisciplina()
        {
          document.formUser.codiceDisciplina.value=document.formUser.elencoDiscipline.value;
        }

        //            function updatePassword(codiceUtente)
        //            {
        //                window.open('updateUserPassword.php?codiceUtente=' + codiceUtente +'','Modifica password','width=400,height=200 ,toolbar=no, location=no,status=yes,menubar=yes,scrollbars=no,resizable=no');
        //            }


        function updatePassword()
        {
          location.href='updateUserPassword.php?codiceUtente=<?= $_COOKIE["codiceUtente"] ?>';
        }

      
        function checkForm()
        {
          var username = document.getElementById('username').value;
          var nome = document.getElementById('nome').value;
          var cognome = document.getElementById('cognome').value;
          var email = document.getElementById('email').value;

          var strErr="";
          if(username.length==0)
            strErr +="1*";
          if(nome.length==0)
            strErr +="3*";
          if(cognome.length==0)
            strErr +="4*";
          if(email.length==0)
            strErr +="5*";
          if(strErr.length>0)
          {
            location.href='../portal/manageErrors.php?noHead=1&lista='+strErr;
            return false;
          }
          else
          {
            return true;
          }

        }

      </script>
    </head>
    <body>

    <?
      if (!isset($_GET["disc"]))
        include '../portal/header.php';
      else
      {
    ?>
        <center>
          <a href='javascript:history.go(-1);'><img src='../images/icons/back.ico' height='30' width='30' title='Indietro' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/utente/utente.php?codiceUtente=<?= $_COOKIE['codiceUtente'] ?>'><img src='../images/icons/PNG/Administrator.png' height='30' width='30' title='<?= $_COOKIE['username'] ?>' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/portal/newMenu.php'><img src='../images/icons/64/home.png' height='30' width='30' title='Home' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/utente/nuovaClasse.php'><img src='../images/icons/128/school.png' height='30' width='30' title='Nuova classe' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/report/searchStudents.php'><img src='../images/icons/128/people.png' height='30' width='30' title='Studenti' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/testManaging/newArgomento.php?codiceUtente=".$_COOKIE["codiceUtente"] ."'><img src='../images/icons/128/phonebook.png' height='30' width='30' title='Gestione Argomenti' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/testManaging/newQuestion.php'><img src='../images/icons/128/plus.png' height='30' width='30' title='Nuova domanda' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/report/reportQuestions.php'><img src='../images/icons/PNG/Document.png' height='30' width='30' title='Cerca Domande' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/testManaging/newTest_1.php'><img src='../images/icons/128/interact.png' height='30' width='30' title='Nuovo test' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/report/searchTest.php'><img src='../images/icons/128/pencil.png' height='30' width='30' title='Test' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/testManaging/reportLiveTest.php'><img src='../images/icons/128/vault.png' height='30' width='30' title='Test sottomessi' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/testManaging/reportPdfLiveTest.php'><img src='../images/icons/128/world.png' height='30' width='30' title='Verifica test' border='0'/></a>
          <a href='<?= $properties->getPath() ?>/portal/logout.php'><img src='../images/icons/PNG/logout.png' height='30' width='30' title='Logout' border='0'/></a>
          <div style="color: red"><h3><b>Scegli le tue discipline prima di proseguire cliccando su Gestione Discipline</b></h3></div>
        </center>
    <? } ?>
      <center>
        <div id="utenteBox">
          <div id="utenteBoxCont">
            <h3><center>Profilo utente</center></h3>
            <form name="formUser" method="POST" action="UtenteListener.php" onsubmit="return checkForm()">
              <input type="hidden" name="username" value="<?php echo $result->getUsername(); ?>" />
              <input type="hidden" name="operation" value="updateUser"/>
              <input type="hidden" name="codice" value="<?php echo $result->getCodice(); ?>" />
              <table width="80%" cellspacing="13" cellpadding="4" style="font-size: 12px;">
                <tr>
                  <td colspan="2"><strong>Attivo:</strong> </td>
                  <td><input type="checkbox" name="attivo" <?php if ($result->getAttivo() == 1)
        echo 'checked' ?> /></td>
              </tr>
              <tr>
                <td colspan="2"><strong>Data registrazione:</strong> </td>
                <td><?php echo $result->getDataCreazione(); ?></td>
              </tr>
              <tr>
                <td colspan="2"><strong>Codice:</strong> </td>
                <td><?php echo $result->getCodice(); ?></td>
              </tr>
              <tr>
                <td colspan="2"><strong>Username:</strong> </td>
                <td><input type="text" id="username" name="username" value="<?php echo $result->getUsername(); ?>" disabled /></td>
              </tr>
              <tr>
                <td colspan="2"><strong>Nome:</strong> </td>
                <td><input type="text" id="nome" name="nome" value="<?php echo $result->getNome(); ?>"/></td>
              </tr>
              <tr>
                <td colspan="2"><strong>Cognome:</strong> </td>
                <td><input type="text" id="cognome" name="cognome" value="<?php echo $result->getCognome(); ?>"/></td>
              </tr>
              <tr>
                <td colspan="2"><strong>E-mail:</strong> </td>
                <td><input type="text" id="email" name="email" value="<?php echo $result->getEmail(); ?>"/></td>
              </tr>
              <?
                         if ($codiceUtente == $_COOKIE["codiceUtente"])
                         {
              ?>
                           <tr>
                             <td colspan="2"><strong>Disciplina:</strong> </td>
                             <td>
                  <?
                           for ($i = 0; $i < count($disciplinaInsegnata); $i++)
                             echo '<strong>' . $disciplinaInsegnata[$i] . '</strong>,';
                  ?>
                         </td>
                         <td>
                           <a href="disciplineUtente.php?noHead=1&codiceUtente=<?= $codiceUtente ?>">Gestione discipline</a>
                         </td>
                       </tr>
              <? } ?>
              <tr>
                <td><input type="submit" value="Modifica" /></td>
                <td><input type="button" value="Modifica Password" onclick="javascript:updatePassword()"/></td>

              </tr>
            </table>
          </form>

        </div>
      </div>
    </center>
  </body>
</html>
